Hệ thống quản lý bệnh viện bằng C# với mã nguồn
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using System.Data.SqlClient;
11
12 namespace HospitalManagementSystemCSharp
13 {
14 public partial class PatientCheckOut : Form
15 {
16 public PatientCheckOut()
17 {
18 InitializeComponent();
19 }
20
21 private void textBox1_TextChanged(object sender, EventArgs e)
22 {
23 SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Sem.4\C# Projects\Trials\HospitalManagementSystemCSharp\HospitalManagementSystemCSharp\hospital.mdf;Integrated Security=True");
24
25 con.Open();
26 if (textBox1.Text != "")
27 {
28 try
29 {
30 string getCust = "select name,gen,age,cont,addr,disease from patient where id=" + Convert.ToInt32(textBox1.Text) + " ;";
31
32 SqlCommand cmd = new SqlCommand(getCust, con);
33 SqlDataReader dr;
34 dr = cmd.ExecuteReader();
35 if (dr.Read())
36 {
37 textBox2.Text = dr.GetValue(0).ToString();
38 if (dr[1].ToString() == "Male")
39 {
40 radioButton1.Checked = true;
41 }
42 else
43 {
44 radioButton2.Checked = true;
45 }
46 textBox3.Text = dr.GetValue(2).ToString();
47 textBox5.Text = dr.GetValue(3).ToString();
48 textBox6.Text = dr.GetValue(4).ToString();
49 textBox7.Text = dr.GetValue(5).ToString();
50
51 }
52 else
53 {
54 MessageBox.Show(" Sorry, This ID, " + textBox1.Text + " patient is not Available. ");
55 textBox1.Text = "";
56 }
57 }
58 catch (SqlException excep)
59 {
60 MessageBox.Show(excep.Message);
61 }
62 con.Close();
63 }
64 }
65
66 private void button1_Click(object sender, EventArgs e)
67 {
68 SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Sem.4\C# Projects\Trials\HospitalManagementSystemCSharp\HospitalManagementSystemCSharp\hospital.mdf;Integrated Security=True");
69 con.Open();
70 string gen = string.Empty;
71 if (radioButton1.Checked)
72 {
73 gen = "Male";
74 }
75 else
76 {
77 gen = "Female";
78 }
79 try
80 {
81 string str = "INSERT INTO checkout(name,gen,age,contact,addr,disease,date_in,date_out,build,r_no,r_type,status,med_price,total) VALUES('" + textBox2.Text + "','" + gen + "','" + textBox3.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','" + textBox10.Text + "','" + textBox11.Text + "','" + textBox12.Text + "','" + textBox14.Text + "','" + textBox13.Text + "','" + textBox15.Text + "'); ";
82
83 SqlCommand cmd = new SqlCommand(str, con);
84 cmd.ExecuteNonQuery();
85 string str1 = "select max(Id) from checkout;";
86
87 SqlCommand cmd1 = new SqlCommand(str1, con);
88 SqlDataReader dr = cmd1.ExecuteReader();
89 if (dr.Read())
90 {
91 MessageBox.Show("Patient Checkout Information Saved Successfully..");
92 textBox2.Text = "";
93 textBox3.Text = "";
94
95 textBox5.Text = "";
96 textBox6.Text = "";
97 textBox7.Text = "";
98 textBox8.Text = "";
99 textBox9.Text = "";
100 textBox10.Text = "";
101 textBox11.Text = "";
102 textBox12.Text = "";
103 textBox13.Text = "";
104 textBox14.Text = "";
105 textBox15.Text = "";
106 }
107 }
108 catch (SqlException excep)
109 {
110 MessageBox.Show(excep.Message);
111 }
112 con.Close();
113 }
114
115 private void button2_Click(object sender, EventArgs e)
116 {
117 textBox2.Text = "";
118 textBox3.Text = "";
119
120 textBox5.Text = "";
121 textBox6.Text = "";
122 textBox7.Text = "";
123 textBox8.Text = "";
124 textBox9.Text = "";
125 textBox10.Text = "";
126 textBox11.Text = "";
127 textBox12.Text = "";
128 textBox13.Text = "";
129 textBox14.Text = "";
130 textBox15.Text = "";
131 }
132 }
133 }